/*
 * Copyright (c) 2009, Jan Pastor. All Rights Reserved.
 */

package sk.jp.jitag.model.config;

import java.util.List;

import sk.jp.jitag.dao.db4o.BaseEntity;
import sk.jp.jitag.dao.db4o.Column;

/**
 * Supported file format.
 */
public class FileFormat extends BaseEntity {

    private static final Column _LABEL = new Column("label");
    private static final Column _DESCRIPTION = new Column("description");

    private String label;
    private String description = "";
    private List<String> extensions = createList(0);
    private List<Tool> tools = createList(0);

    //----------------------------------------------------------------------

    public FileFormat(String label) {
        checkNotNullNotEmpty(_LABEL, label);
        checkMaxLen(_LABEL, label, 15);
        checkMaxLen(_DESCRIPTION, description, 25);

        this.label = label;
    }

    //----------------------------------------------------------------------

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        checkNotNullNotEmpty(_LABEL, label);
        checkMaxLen(_LABEL, label, 15);

        this.label = label;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description == null ? "" : description;
        checkMaxLen(_DESCRIPTION, description, 25);
    }

    public List<String> getExtensions() {
        return extensions;
    }

    public FileFormat addExtension(String extension) {
        if(!extensions.contains(extension)){
            extensions.add(extension);
        }
        return this;
    }

    public void removeExtension(String extension){
        extensions.remove(extension);
    }

    public List<Tool> getTools() {
        return tools;
    }

    public void addTool(Tool tool){
        if(!tools.contains(tool)){
            tools.add(tool);
        }
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("FileFormat");
        sb.append("{label='").append(label).append('\'');
        sb.append(", description='").append(description).append('\'');
        sb.append(", extensions=").append(extensions);
        sb.append(", tools=").append(tools);
        sb.append('}');
        return sb.toString();
    }
}
